package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author dongdong 抖音号：W13883155245
 * @version 1.0
 * @date 2025/8/18
 * @description
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺接口")
public class Shopcontroller {
    public static final String KEY = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 设置店铺状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺状态")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺状态{}",status==1?"营业中":"已打样");
        redisTemplate.opsForValue().set(KEY, status);
        return Result.success();
    }

    /**
     * 查询状态
     * @return
     */
    @GetMapping("/status")
    public Result<Integer> getStatus(){
       Integer status=(Integer) redisTemplate.opsForValue().get(KEY);
        log.info("设置店铺状态{}",status==1?"营业中":"已打样");
        return Result.success(status);
    }
}
